const express = require('express');
const expressStatic= require('express-static');

const server = express();


// 接口定义
// login?user=xxx&pass=xxx;
let users = {
    'blue': '12345',
    'zhangsan': '1234567'
}

/**
 * 如果是请求直接走get，否则走下边而静态文件读取;
 */
server.use('/login', (req, res) => {
    // console.log(req.query);
    let user = req.query['user'];
    let pass = req.query['pass'];

    if (!users[user]) {
        res.send({ok: false, msg: '此用户不存在'});
    } else {
        if (users[user] != pass) {
            res.send({ ok: false, msg: '密码不正确' });
        } else {
            res.send({ ok: true, msg: '登录成功' });
        }
    }
    // res.end();
});

server.use(expressStatic('./www'), (req, res) => {
    // res.send('b.html');
    // res.end();
});


server.listen(8080, () => {
    console.log('启动成功');
})